<template>
  <div class="question-list">
    <!-- Loading骨架屏 -->
    <div v-if="loading" class="skeleton-container">
      <div v-for="i in 5" :key="i" class="skeleton-item">
        <div class="skeleton-card">
          <div class="skeleton-header">
            <div class="skeleton-tags">
              <div class="skeleton-tag"></div>
              <div class="skeleton-tag"></div>
            </div>
          </div>
          <div class="skeleton-title"></div>
          <div class="skeleton-content">
            <div class="skeleton-line"></div>
            <div class="skeleton-line"></div>
          </div>
          <div class="skeleton-meta">
            <div class="skeleton-meta-item"></div>
            <div class="skeleton-meta-item"></div>
            <div class="skeleton-meta-item"></div>
          </div>
          <div class="skeleton-user">
            <div class="skeleton-avatar"></div>
            <div class="skeleton-username"></div>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 实际内容 -->
    <div v-else>
      <QuestionListItem
        v-for="q in questions"
        :key="q.id"
        :question="q"
        :activeTab="activeTab"
        @click.native="emit('goDetail', q.id)"
      >
        <template #default="slotProps">
          <slot name="item" v-bind="slotProps" />
        </template>
      </QuestionListItem>
    </div>
  </div>
</template>
<script setup>
import QuestionListItem from './QuestionListItem.vue'
const props = defineProps({
  questions: Array,
  activeTab: String,
  loading: {
    type: Boolean,
    default: false
  }
})
const emit = defineEmits(['goDetail'])
</script>
<style scoped>
.question-list {
  flex: 1 1 0;
  min-height: 0;
  margin-top: 0;
  padding-bottom: 8px;
  position: relative;
}

/* 骨架屏样式 */
.skeleton-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.skeleton-item {
  background: #fff;
  border-radius: 13px;
  padding: 16px 18px 12px 18px;
  box-shadow: 0 2px 10px 0 rgba(56,112,255,0.08);
  border: none;
}

.skeleton-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.skeleton-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.skeleton-tags {
  display: flex;
  gap: 8px;
}

.skeleton-tag {
  width: 60px;
  height: 20px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  border-radius: 10px;
  animation: skeleton-loading 1.5s infinite;
}

.skeleton-title {
  width: 80%;
  height: 20px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: skeleton-loading 1.5s infinite;
}

.skeleton-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-line {
  height: 14px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: skeleton-loading 1.5s infinite;
}

.skeleton-line:first-child {
  width: 100%;
}

.skeleton-line:last-child {
  width: 70%;
}

.skeleton-meta {
  display: flex;
  gap: 16px;
  align-items: center;
}

.skeleton-meta-item {
  width: 50px;
  height: 12px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: skeleton-loading 1.5s infinite;
}

.skeleton-user {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.skeleton-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
}

.skeleton-username {
  width: 60px;
  height: 12px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* 响应式设计 */
@media (max-width: 700px) {
  .skeleton-item {
    padding: 12px 14px 8px 14px;
  }
  
  .skeleton-tag {
    width: 50px;
    height: 16px;
  }
  
  .skeleton-title {
    height: 18px;
  }
  
  .skeleton-line {
    height: 12px;
  }
  
  .skeleton-meta-item {
    width: 40px;
    height: 10px;
  }
  
  .skeleton-avatar {
    width: 18px;
    height: 18px;
  }
  
  .skeleton-username {
    width: 50px;
    height: 10px;
  }
}
</style> 